<template>
  <div>
    <!--1.视图-->
    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="代办编号" align="center" key="taskId" prop="taskId" />-->
<!--      <el-table-column label="代办昵称" align="center" key="taskName" prop="taskName" />-->
<!--      <el-table-column label="代办名称" align="center" key="taskAssignee" prop="taskAssignee" />-->
      <el-table-column label="实例编号" align="center" key="procId" prop="procId" />
      <el-table-column label="请假编号" align="center" key="leaveId" prop="leaveId" />
      <el-table-column label="请假名称" align="center" key="leaveName" prop="leaveName" />
      <el-table-column label="请假标题" align="center" key="title" prop="title"/>
      <el-table-column label="请假原因" align="center" key="reason" prop="reason" />
      <el-table-column label="请假送审人" align="center" key="proposer" prop="proposer"/>
      <el-table-column label="请假附件图片" align="center" key="leaveImg" prop="leaveImg">
        <template v-slot="s">
          <img :src="s.row.leaveImg" style="width: 100px;height: 100px;">
          </img>
        </template>
      </el-table-column>
      <el-table-column label="请假天数" align="center" key="days" prop="days"/>
      <el-table-column label="请假状态" align="center" key="status" prop="status">
        <template v-slot="s">
          <el-button  size="mini" type="info" v-if="s.row.status==0">未申请</el-button>
          <el-button  size="mini" type="success" v-if="s.row.status==1">已申请</el-button>
          <el-button  size="mini" type="info" v-if="s.row.status==2">未驳回</el-button>
          <el-button  size="mini" type="danger" v-if="s.row.status==3">已驳回</el-button>
        </template>
      </el-table-column>
      <el-table-column label="请假备注" align="center" key="remark" prop="remark"/>
      <el-table-column label="开始时间" align="center" key="startTime" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束时间" align="center" key="endTime" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="songsheng(scope.row)">盖章审批</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="xq(scope.row)">审批详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="tongyi(scope.row)">审批</el-button>
          <el-button v-if="scope.row.taskName=='项目经理'" size="mini" type="text" icon="el-icon-edit" @click="bohui(scope.row)">驳回</el-button>
          <el-button v-if="scope.row.taskName=='总经理'" size="mini" type="text" icon="el-icon-edit" @click="bohui(scope.row)">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>


    <el-dialog :title="title"  :visible.sync="dialogFormVisible">
      <el-form :model="form"  label-width="80px">
        <h1>请假人:{{loginName}}</h1>

        <el-row>
          <el-col :span="12">
            <el-form-item label="请假标题" prop="title">
              <el-input v-model="form.title" placeholder="请输入请假标题" />
            </el-form-item>
          </el-col>
        </el-row>
         <el-row>
          <el-col :span="12">
            <el-form-item label="请假天数" prop="title">
              <el-input v-model="form.days" placeholder="请输入请假天数" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="送审人" prop="title">
              <el-input v-model="form.proposer" placeholder="请输入请假标题" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="开始时间" prop="startTime">
              <el-date-picker
                v-model="timeValue"
                type="datetimerange"
                value-format="yyyy-MM-dd HH:mm:ss"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="请假原因" prop="reason">
              <el-input v-model="form.reason" placeholder="请输入请假原因" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="审批意见" prop="proposer">
              <el-radio-group v-model="form.flag">
                <el-radio label="0" value="0">同意</el-radio>
                <el-radio label="1" value="1">不同意</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {selectTaskList, selectComplete, getLeave, goApply} from "@/api/note/applys";
import user from "@/store/modules/user";

export default {
  name: "index",
  data() {
    return {
      //2.属性定义
      loginName: user.state.name,
      dialogFormVisible:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      timeValue: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      dataList: [],
      // 默认字典类型
      defaultLeaveType: "",
      // 弹出层标题
      title: "",
      // 类型数据字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        LeaveName: undefined,
        proposer: undefined,
        title: undefined
      },
      // 表单参数
      form: {},
      flag:0,
    }
  }, methods: {
    //3.方法
    submitForm(){
        goApply(this.form.procId,this.form.proposer,this.form.days,this.form.flag).then(r=>{
          this.dialogFormVisible=false;
          this.getList();
        })
    },
    /** 审批按钮操作 */
    songsheng(row){
      let procId = row.procId;
      goApply(procId,"wy",row.days,this.flag).then(r=>{
        this.getList();
      })
    },
    xq(row){
      this.form.leaveName=this.loginName;
      const leaveId = row.leaveId || this.ids;
      this.timeValue=[];
      getLeave(leaveId).then(response => {
        this.form = response.data;
        this.timeValue.push(this.form.startTime);
        this.timeValue.push(this.form.endTime);
        this.dialogFormVisible =  true;
      });
    },
    tongyi(row){
      selectComplete({
        taskId:row.taskId,
        taskName:row.taskName,
        status:row.status,
        days:row.days,
        flag:0,
      }).then(r=>{
        this.getList();
      })
    },
    bohui(row){
      selectComplete({
        taskId:row.taskId,
        taskName:row.taskName,
        status:row.status,
        days:row.days,
        flag:1,
      }).then(r=>{
        this.getList();
      })
    },
    getList(){
      this.loading=true;
      selectTaskList(this.queryParams).then(r=>{
        this.dataList = r.rows;
        this.total=r.total;
        this.loading=false;
      })
      // selectTaskList(this.queryParams).then(r=>{
      //   this.dataList = r;
      //   this.loading=false;
      // })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.leaveId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.LeaveName = this.defaultLeaveType;
      this.handleQuery();
    },
  }, created() {
    //4.钩子函数
    this.getList();
  }
}
</script>

<style scoped>

</style>
